package cn.afactory.tygz.model;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

/**
 * Created with Android Studio.
 * Title:SecondGoodsInfo
 * Description:
 * Copyright:Copyright (c) 2015
 * Company:和平必胜、正义必胜、人民必胜
 * Author:炎黄子孙
 * Date:15/9/11
 * Time:下午3:44
 * Version 1.0
 */
public class ExchangeGoodInfo implements Serializable{
    private static final long serialVersionUID = 3246451692600706144L;

    public long id;

    public String name;

    public String desc;

    public int money;

    public long addTime;
    //兑换的状态（0 代表兑换成功 1代表兑换失败，2正在兑换中）
    public int state;
    /**
     * 反序列化函数，用于从json字符串反序列化本类型实例
     */
    public static ExchangeGoodInfo deserialize(String json) throws JSONException {
        if (json != null && !json.isEmpty()) {
            return deserialize(new JSONObject(json));
        }
        return null;
    }

    /**
     * 反序列化函数，用于从json节点对象反序列化本类型实例
     */
    public static ExchangeGoodInfo deserialize(JSONObject json) throws JSONException {
        if (json != null && json != JSONObject.NULL && json.length() > 0) {
            ExchangeGoodInfo result = new ExchangeGoodInfo();

            result.id = json.optLong("id");

            result.addTime = json.optLong("addTime");

            if (!json.isNull("name")) {
                result.name = json.optString("name", null);
            }

            if (!json.isNull("desc")) {
                result.desc = json.optString("desc", null);
            }

            result.money = json.optInt("money");

            result.state = json.optInt("state");

            return result;
        }
        return null;
    }
}
